package com.artisan.provider.service.impl;

import com.artisan.provider.domain.ZgIntegral;
import com.artisan.provider.dto.ZgIntegralDto;
import com.artisan.provider.mapper.ZgIntegralMapper;
import com.artisan.provider.service.ZgIntegralService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZgIntegralServiceImpl implements ZgIntegralService {

    @Autowired
    ZgIntegralMapper zgIntegralMapper;

    @Override
    public List<ZgIntegral> findAll(ZgIntegralDto zgIntegralDto, int page, int limit) {
        if(page > 0 && limit > 0){
            PageHelper.startPage(page,limit);
        }
        return zgIntegralMapper.findAll(zgIntegralDto);
    }

    @Override
    public int zgIntegralAdd(ZgIntegral zgIntegral) {
        int i = 0;
        try {
           return zgIntegralMapper.insertSelective(zgIntegral);
        }catch (Exception e){
            return i;
        }
    }

    @Override
    public int zgIntegralUpdate(ZgIntegral zgIntegral) {
        int i = 0;
        try {
            return zgIntegralMapper.updateByPrimaryKeySelective(zgIntegral);
        }catch (Exception e){
            return i;
        }
    }

    @Override
    public int zgIntegralDelete(int id) {
        return zgIntegralMapper.deleteByPrimaryKey(id);
    }
}
